home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / boss_c.arc / POPUP.C < prev    next >
Text File  |  1986-10-01  |  6KB  |  142 lines

  1. /*
  2. ** POPUP - Popup Menu/Window Driver
  3. **
  4. ** Copyright (C) 1985 - Philip A. Mongelluzzo
  5. ** All rights reserved.
  6. **
  7. */
  8.  
  9. #include "windows.h"                    /* window header */
  10.  
  11. #define UARROW  0x48                    /* define scan codes */
  12. #define DARROW  0x50
  13. #define LARROW  0x4b
  14. #define RARROW  0x4d
  15. #define BS      0x0e
  16. #define DEL     0x53
  17. #define RET     0x1c
  18. #define ESC     0x01
  19. #define SPACE   0x39
  20.  
  21. #define TRUE    1
  22. #define FALSE   0
  23.  
  24. /*
  25. ** Popup structure templates
  26. */
  27.  
  28.   struct mitem {                        /* menu item template */
  29.     int r;                              /* row */
  30.     int c;                              /* col */
  31.     char *t;                            /* text */
  32.     int rv;                             /* return value */
  33.   };
  34.  
  35.   struct pmenu {                        /* popup menu structure */
  36.     int fm;                             /* first menu item index */
  37.     int lm;                             /* last menu item index */
  38.     struct mitem scrn[25];              /* a bunch of menu items */
  39.   };
  40.  
  41. /*
  42. *********
  43. * popup *
  44. *********
  45. */
  46.  
  47. popup(page,row,col,width,height,atrib,batrib,mx,cflag)
  48. int page;                               /* video page */
  49. int row, col;                           /* window - upper row/col */
  50. int width, height;                      /* window - height & width */
  51. struct pmenu *mx;                       /* pointer to popup menu struct */
  52. int cflag;                              /* close on return strike flag */
  53. int atrib, batrib;                      /* attributes - window & border */
  54. {
  55. int i;                                  /* scratch integer */
  56. WINDOWPTR w;                            /* window pointer */
  57. static WINDOWPTR wpsave;                /* a place to remember it */
  58. int c;                                  /* key scan code,,char */
  59. static winopn = FALSE;                  /* window currently open flag */
  60. static lndx = 0;                        /* last open window item index */
  61.  
  62.   if(winopn) {                          /* window is still open */
  63.     goto d0;                            /* enter processing loop */
  64.   }
  65.   lndx = -1;                            /* set index out of range */
  66.   w = wn_open(page, row, col, width, height, atrib, batrib);
  67.   wn_sync(w,TRUE);                      /* sync cursor */
  68.   wpsave = w;                           /* save pointer */
  69.   if (w == NULL) return(99);            /* out of mem or just fubar */
  70.   winopn = TRUE;                        /* say window is open */
  71.  
  72.   i = 0;                                /* init index */
  73.   while(mx->scrn[i].r) {                /* for as long as we have data */
  74.     wn_puts(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t);
  75.     i++;
  76.   }
  77.  
  78. d0:
  79.   w = wpsave;                           /* restore pointer */
  80.   i = lndx;                             /* BLINDLY assume that we're back */
  81.   if(i < mx->fm) i = mx->fm;            /* and reset if "i" is now out of */
  82.   if(i > mx->lm) i = mx->fm;            /* range - (dumb, but it works) */
  83.   while(TRUE) {                         /* till we exit */
  84.     wn_locate(w, mx->scrn[i].r, mx->scrn[i].c);
  85.     c = v_getch() >> 8;                 /* see whats goin' on */
  86.     if(c == ESC) break;                 /* ESC (user wants out) - swk */
  87.     if(c == RET) {                      /* swk RETURN */
  88.       if(cflag) {                       /* close window on return strike ? */
  89.         wn_close(w);                    /* close the window */
  90.         winopn = FALSE;                 /* say window is closed */
  91.       }
  92.       lndx = i;                         /* remember last indx */
  93.       return(mx->scrn[i].rv);           /* return with rv */
  94.     }
  95.     if(c == DARROW) c = SPACE;          /* swk conversion */
  96.     if(c == RARROW) c = SPACE;          /* swk conversion */
  97.     if(c == LARROW) c = BS;             /* swk conversion */
  98.     if(c == UARROW) c = BS;             /* swk conversion */
  99.     if(c == SPACE || c == DEL || c == BS) {
  100.       if(c == SPACE)                    /* foreward ?? */
  101.         i++;                            /* bump index */
  102.       else
  103.         i--;                            /* decrement */
  104.       if(i < mx->fm) i = mx->lm;        /* wrap on either */
  105.       if(i > mx->lm) i = mx->fm;        /* end */
  106.     }                                   /* endif */
  107.   }                                     /* end while */
  108.   wn_close(w);                          /* bye bye */
  109.   winopn = FALSE;                       /* say window is closed */
  110.   return(99);                           /* nothing selected */
  111. }
  112.  
  113. #ifdef COMMENTS                                                  
  114. /*
  115. **********                              /* quick popup... */
  116. * qpopup *                              /* this is a hack of popup */
  117. **********                              /* but the code fragment */
  118. */                                      /* could be of value */
  119. #endif
  120.  
  121. WINDOWPTR qpopup(page,row,col,width,height,atrib,batrib,mx)
  122. int page;                               /* video page */
  123. int row, col;                           /* window - upper row/col */
  124. int width, height;                      /* window - height & width */
  125. int atrib, batrib;                      /* atributes - window & border */
  126. struct pmenu *mx;                       /* pointer to text struct */
  127. {
  128. int i;                                  /* scratch integer */
  129. WINDOWPTR w;                            /* window pointer */
  130.  
  131.   w = wn_open(page, row, col, width, height, atrib, batrib);
  132.  
  133.   i = 0;                                /* init index */
  134.   while(mx->scrn[i].r) {                /* for as long as we have data */
  135.     wn_puts(w, mx->scrn[i].r, mx->scrn[i].c, mx->scrn[i].t);
  136.     i++;
  137.   }
  138.   return(w);
  139. }
  140.  
  141. /* End */
  142.